using AdminFrame.Application.Contracts.Parameters;
using AdminFrame.Application.Contracts.Parameters.Dtos;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;
using Volo.Abp.AspNetCore.Mvc.UI.RazorPages;

namespace AdminFrame.Web.Pages.Parameters
{
    public class EditModalModel : AbpPageModel
    {
        [HiddenInput]
        [BindProperty(SupportsGet = true)]
        public Guid Id { get; set; }

        [BindProperty]
        public ParameterUpdateViewModel Parameter { get; set; }

        protected IParameterAppService _parameterAppService;

        public EditModalModel(IParameterAppService parameterAppService)
        {
            _parameterAppService = parameterAppService;

            Parameter = new();
        }

        public virtual async Task OnGetAsync()
        {
            var parameter = await _parameterAppService.GetAsync(Id);
            Parameter = ObjectMapper.Map<ParameterDto, ParameterUpdateViewModel>(parameter);

        }

        public virtual async Task<NoContentResult> OnPostAsync()
        {

            await _parameterAppService.UpdateAsync(Id, ObjectMapper.Map<ParameterUpdateViewModel, CreateUpdateParameterDto>(Parameter));
            return NoContent();
        }
    }

    public class ParameterUpdateViewModel : CreateUpdateParameterDto
    {
    }

}